package com.jerry.security.model;

import java.io.Serializable;

/**
 * @author Jerry.Wu
 * @description:
 * @date 2018/9/3 15:57
 */
public class ReturnVO<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int SUCCESS_CODE = 0;

    public static final int ERROR_CODE = -1;

    private T data;

    private int code;

    private String msg;

    public ReturnVO() {

    }

    public ReturnVO(T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static<T> ReturnVO<T> OK() {
        return ReturnVO.OK(null);
    }

    public static<T> ReturnVO<T> OK(T data) {
        return ReturnVO.OK(data, "");
    }

    public static<T> ReturnVO<T> OK(T data, String msg) {
        ReturnVO rv = new ReturnVO(data, SUCCESS_CODE, msg);
        return rv;
    }

    public static<T> ReturnVO<T> NG() {
        return ReturnVO.NG(null, "");
    }

    public static<T> ReturnVO<T> NG(String msg) {
        return ReturnVO.NG(null, msg);
    }

    public static<T> ReturnVO<T> NG(T data, String msg) {
        ReturnVO rv = new ReturnVO(data, ERROR_CODE, msg);
        return rv;
    }

}
